<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin('jy_jdpm/member.index/');
$return=array();
if($_RQ['op']=='main'){
		if ($post) {

        } else {
            // 用户消息
            $ucwer = array('mid'=>$_SESSION['uid']);
			//"(aid != 0 and uid=" . $_SESSION['uid'] . ") or (uid=" . $_SESSION['uid'] . " and sendid != 0)";
            // 系统消息
            $scwer = array('uniacid'=>$_SESSION['uniacid'],'mid' => $_SESSION['uid'] , 'sendid' => 0 , 'aid' => 0);
            $where = $scwer;
            if ($_RQ['tp'] == 'usend') {
                $where = $ucwer;
            } else {
                $where = $scwer;
            }
            // 统计未读
            $ucwer['status']  = 0;
            $ucwer['delmark'] = 0;
            $scwer['status']  = 0;
            $scwer['delmark'] = 0;
            $return['sc']     = pdo_count('jy_jdpm_mysms',$scwer,'id');
            $return['uc']     = pdo_count('jy_jdpm_mysms',$ucwer,'id');

            // 读取列表到页面
            $where['delmark'] = 0;
			$pindex = max(1, intval($_RQ['page']));
			$psize = 200;
			$total='';
			$slist=pdo_getslice('jy_jdpm_mysms',$where,array($pindex,$psize),$total,$fields);
			
			foreach($slist as &$v){
				$v['user']    = get_member($v['sendid']);
                $v['content'] = preg_replace("/<a[^>]*>(.*?)<\/a>/is" , "$1" , $v['content']);
                if ($v['pid']) {
                    $v['auction']      = pdo_get('jy_jdpm_auction',array('mid' => $v['sendid']),array('id','pname'));
                    $v['auction']['pname'] = mb_substr($v['auction']['pname'] , 0 , 20 , 'utf-8') . '...';
                }
			}
            $totalpage=ceil($total/$psize);
			$totalpage=intval($totalpage);
			$return['totalpage'] =$totalpage;
			$return['params']['page'] =$pindex;
			$return['tp']=$_RQ['tp'];
			$return['slist']=$slist;
			set_html('title','我的消息');
		exi($return);
	}
}
if($_RQ['op']=='set'){
	       $sid   = $_RQ['id'];
            $where = array('id' => array('in' , $sid));
            if ( $_RQ['ac'] == 'del') {
                $count = pdo_update('jy_jdpm_mysms',array('delmark'=>1),$where);
                $t     = '删除';
            } elseif ($_RQ['ac'] == 'read') {
				$count = pdo_update('jy_jdpm_mysms',array('status'=>1),$where);
                $t     = '设置已读';
            }
            if ($count) {
                exi($t . "成功" ,'error');
            } else {
				exi($t . "失败，请重试" ,'error');
       }
}
if($_RQ['op']=='notice'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['isread'])){
		$params['isread']=intval($_RQ['isread']);
		$return['params']['isread'] =intval($_RQ['isread']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_jdpm_notice_log',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			if(!$item['isread']){
				pdo_update('jy_jdpm_notice_log',array('isread'=>1),array('id'=>$item['id']));
			}
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['list']=$list;
	exi($return);
}